package umich.max.geolocation.experiments;

import java.io.File;
import java.util.List;

import org.apache.log4j.Logger;

import max.nlp.util.Experiment;
import max.nlp.wrappers.ml.weka.WekaFeatureBuilder;
import max.nlp.wrappers.ml.weka.WekaFeatureExtractor;
import umich.max.geolocation.featextract.builders.BlogFeatureBuilder;
import umich.max.geolocation.featextract.builders.BlogsWithLocFeatureBuilder;
import umich.max.geolocation.featextract.builders.BlogManyFeatureBuilder;
import umich.max.geolocation.featextract.builders.PostFeatureBuilder;
import umich.max.geolocation.featextract.ner.LocationBooleanExtractor;
import umich.max.geolocation.featextract.ner.LocationCounterExtractor;
import umich.max.geolocation.featextract.ner.MostProbableNStatesExtractor;
import umich.max.geolocation.featextract.ner.PercentLocsInStateExtractor;
import umich.max.geolocation.featextract.tf.blog.TFICFPerBlogComputer;
import umich.max.geolocation.featextract.tf.blog.TFPerBlogComputer;

public class BlogExperiment extends Experiment{

	protected static Logger log = Logger.getLogger(ClassifyNStates.class);

	public WekaFeatureExtractor getExtractor(String name) {
		if (name.equals("tf"))
			return new TFPerBlogComputer();
		else if (name.equals("tficf"))
			return new TFICFPerBlogComputer();
		else if (name.equals("bLoc"))
			return new LocationCounterExtractor();
		else if (name.equals("iLoc"))
			return new LocationBooleanExtractor();
		else if (name.equals("mpLoc"))
			return new MostProbableNStatesExtractor();
		else if (name.equals("perLoc"))
			return new PercentLocsInStateExtractor();
		return null;
	}
	
	public WekaFeatureBuilder getFeatureBuilder(String name){
		WekaFeatureBuilder fb = null;
		if (name.equals("blog"))
			fb = new BlogFeatureBuilder();
		else if (name.equals("blog2"))
			fb  = new BlogManyFeatureBuilder();
		else if (name.equals("blog3"))
			fb  = new BlogsWithLocFeatureBuilder();
		else if (name.equals("post"))
			fb = new PostFeatureBuilder();
	
		return fb;
	}

	public WekaFeatureBuilder getFeatureBuilder(String fbType, List<String> extractors) {
		WekaFeatureBuilder fb = getFeatureBuilder(fbType);
		for (String extractor : extractors) {
			WekaFeatureExtractor featureExtractor = getExtractor(extractor);
			if (featureExtractor == null) {
				log.fatal(extractor
						+ " is not a valid type of feature extractor");
				System.exit(0);
			} else {
				fb.addFeatureExtractor(featureExtractor);
			}
		}
		return fb;
	}

	public void setupDirectory(String dirPath) {
		try {
			File dir = new File(dirPath);

			if (!dir.exists() || !dir.isDirectory())
				dir.mkdir();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
}
